package edu.poly.game.stats;

import java.util.ArrayList;
import java.util.List;

import edu.poly.game.battleship.BattleShipType;

public class GameStats {
	private int totalNumberOfMissiles;
	
	//counters
	private int numberOfMissilesUsed;
	private int numberOfSuccessHits;
	private int numberOfMissedHits;
	
	private List<BattleShipType> destroyedShips;
	
	public GameStats(final int totalNumberOfMissiles) {
		this.totalNumberOfMissiles = totalNumberOfMissiles;
		this.destroyedShips = new ArrayList<BattleShipType>();
	}
	
	public void incrementSuccessHit() {
		this.numberOfSuccessHits++;
	}
	
	public void incrementMissedHit() {
		this.numberOfMissedHits++;
	}
	
	public void incrementMissileUsed() {
		this.numberOfMissilesUsed++;
	}
	
	public void addShipDestroyed(final BattleShipType shipType) {
		this.destroyedShips.add(shipType);
	}
	
	public int getTotalNumberOfMissiles() {
		return totalNumberOfMissiles;
	}

	public int getNumberOfMissilesUsed() {
		return numberOfMissilesUsed;
	}

	public int getNumberOfSuccessHits() {
		return numberOfSuccessHits;
	}

	public int getNumberOfMissedHits() {
		return numberOfMissedHits;
	}
	
	public int getNumberOfMissilesLeft() {
		return this.totalNumberOfMissiles - this.getNumberOfMissilesUsed();
	}

	public List<BattleShipType> getDestroyedShips() {
		return destroyedShips;
	}

	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append("Number of missiles used = ").append(this.numberOfMissilesUsed).append("\n");
		sb.append("Number of missiles left = ").append(this.totalNumberOfMissiles - this.numberOfMissilesUsed).append("\n");
		sb.append("Number of hits = ").append(this.numberOfSuccessHits).append("\n");
		sb.append("Number of misses = ").append(this.numberOfMissedHits).append("\n");
		sb.append("Opponent ships destroyed = ");
		if(this.destroyedShips != null && this.destroyedShips.size() > 0) {
			for(BattleShipType type : this.destroyedShips) {
				sb.append(type.getName()).append(", ");
			}
		}
		return sb.toString();
	}
}
